<?php
require_once('../../config.php');
global $CFG, $USER, $COURSE;
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$role = get_user_roles($context, $USER->id);
require_js($CFG->wwwroot.'/blocks/library_reserve/libres.js');
$cat_id = array('', 'Call No.', 'ISBN No.', 'Please order.');
$cat_tb = array('', 'call_num', 'isbn_num', '');
$months = array('', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$navigation = build_navigation();
print_header('Physical reserve requests', 'Physical reserve requests', $navigation);
foreach($role as $r){
	if($r->roleid == 8||$r->roleid == 1){
		$access = true;
	}
}
if($access){
	$rs = get_records('libres', '', '', 'timecreated');
	echo '<div id="libres_container" style="padding:5px;">';
	foreach($rs as $op){
		echo '<div style="font-size:12px;float:left;border:1px solid #000;margin-left:4px;padding:4px;max-width:250px">';
		$course = get_record_sql("SELECT fullname FROM {$CFG->prefix}course WHERE id=$op->course");
		$date = new DateTime($op->timecreated);
		$date->modify('+14 days');
		$month = $date->format("m");
		echo "<p style=\"color:red;font-weight:bold;font-size:14px;\">Due date: ".$months[intval($month)]." ".$date->format("d Y")."</p>";
		echo "<p><b>Course:</b> $course->fullname</p>";
		$user = get_record_sql("SELECT firstname, lastname, email FROM {$CFG->prefix}user WHERE id=$op->user");
		echo "<p><b>Instructor:</b> $user->firstname $user->lastname (<a href=\"mailto:$user->email\">$user->email</a>)</p>";
		$req_type = get_record_sql("SELECT description FROM {$CFG->prefix}request_types WHERE id=$op->req_type");
		echo "<p><i>$req_type->description</i></p>";
		$req_type = $op->req_type;
		echo "<div style=\"background-color:#ccc;padding:2px;\"><b>$op->title, $op->author</b></div>";
		echo "<p><b>$cat_id[$req_type]:</b> ".$op->{$cat_tb[$req_type]}."</p>";
		echo '<form id="status'.$op->id.'">';
		echo '<input type="radio" name="req_status" id="req_status" value="0" ';
		if($op->processing == 0){echo 'checked="true"';}
		echo " />is not being processed.<br />";
		echo '<input type="radio" name="req_status" id="req_status" value="1" ';	
		if($op->processing == 1){echo 'checked="true"';}
		echo '/>is being processed.<br />';
		echo '<input type="radio" name="req_status" id="req_status" value="2" ';
		if($op->processing == 2){echo 'checked="true"';}
		echo '/>has been processed.<br />';
		echo '</form>';
		echo '<p style="text-align:center;"><a href="#" onclick="set_request_status('.$op->id.', document.getElementById(\'status'.$op->id.'\'), \''.$CFG->wwwroot.'\'); return false;">Save</a></p>';
		echo '</div>';
	}
	echo '<br style="height:0px;clear:both;" />';
	echo '</div>';
}else{
	echo '<div style="font-size:14px;font-weight:bold;color:red;">Sorry, you do not have permission to view this page.</div>';
}
print_footer();
?>
